# 最大连续子数组和


class Solution:

    def maxSubArray(self, nums):
        if not nums:
            return 0
        size = len(nums)
        dp = [0] * size

        dp[0] = nums[0]

        for i in range(1, size):
            if dp[i - 1] > 0:
                dp[i] = dp[i - 1] + nums[i]
            else:
                dp[i] = nums[i]

        
        return max(dp)
    


if __name__ == "__main__":

    nums = [-2,1,-3,4,-1,2,1,-5,4]
    sol = Solution()
    res = sol.maxSubArray(nums)
    print(res)



